package model.impl;

import sharedGameLogic.enums.BattleEvent;

class MenuItemHandler {
	
	void reset() {
		for (int i = 0; i < currentMarked.length; i++) {
			currentMarked[i] = 0;
		}
		currentMenuLevel = 0;
	}
	
	void goIntoSubMenu() {
		if (currentMenuLevel < 2) {
			currentMenuLevel++;
			currentMarked[currentMenuLevel] = 0;
		} else {
			reset();
		}
	}
	
	void goBackToSuperMenu() {
		if (currentMenuLevel > 0) {
			currentMenuLevel--;
			currentMarked[currentMenuLevel] = 0;
		}
	}
	
	BattleEvent getCurrentAction() {
		if (currentMenuLevel == 2) {
			return actions[currentMarked[0]][currentMarked[1]][currentMarked[2]];
		}
		return null;
	}
	
	void nextMenuItem() {
		currentMarked[currentMenuLevel]++;
		
		currentMarked[0] %= actions.length;
		currentMarked[1] %= actions[currentMarked[0]].length;
		currentMarked[2] %= actions[currentMarked[0]][currentMarked[1]].length;
	}
	
	void previousMenuItem() {
		currentMarked[currentMenuLevel]--;
		
		
		currentMarked[0] += actions.length;
		currentMarked[0] %= actions.length;
		
		currentMarked[1] += actions[currentMarked[0]].length;
		currentMarked[1] %= actions[currentMarked[0]].length;
		
		currentMarked[2] += actions[currentMarked[0]][currentMarked[1]].length;
		currentMarked[2] %= actions[currentMarked[0]][currentMarked[1]].length;
	}
	
	int[] getMenuPosition() {
		switch (currentMenuLevel) {
		case 0:
			int[] i = {currentMarked[0]};
			return i;
		case 1:
			int[] j = {currentMarked[0], currentMarked[1]};
			return j;
		case 2:
			return currentMarked;
		}
		return currentMarked;
	}
	
	int getCurrentLevel() {
		return currentMenuLevel;
	}
	
	private int[] currentMarked = {0,0,0};
	private int currentMenuLevel = 0;
	private static final BattleEvent[] offensive = 	
			{
				BattleEvent.STRONG_ATTACK,
				BattleEvent.FAST_ATTACK, 
				BattleEvent.PRECISE_ATTACK
			};
	private static final BattleEvent[] ranged = 
			{
				BattleEvent.RANGED_STRONG_ATTACK,
				BattleEvent.RANGED_FAST_ATTACK,
				BattleEvent.RANGED_PRECISE_ATTACK				
			};
	private static final BattleEvent[] defensive = 	
			{
				BattleEvent.BLOCK, BattleEvent.DODGE,
				BattleEvent.COUNTER
			};
	
	private static final BattleEvent[] strategic =	
			{
				BattleEvent.CHARGE, BattleEvent.RETREAT
			};
	
	private static final BattleEvent[] elemental = 
			{
				BattleEvent.MAGIC_FIRE, BattleEvent.MAGIC_WATER,
				BattleEvent.MAGIC_WIND, BattleEvent.MAGIC_WOOD
			};
	
	private static final BattleEvent[] enhanced =
			{
				BattleEvent.MAGIC_STRONG_ATTACK,
				BattleEvent.MAGIC_FAST_ATTACK,
				BattleEvent.MAGIC_PRECISE_ATTACK
			};
	
	private static final BattleEvent[][] physical = {offensive, ranged, defensive, strategic};
	private static final BattleEvent[][] magical = {elemental};
	private static final BattleEvent[][] combined = {enhanced};
	
	private static final BattleEvent[][][] actions = {physical, magical, combined};
}